package com.itheima.chapter08.set.map.hashmap;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

//HashMap存储老师对象
//保证键的唯一性，通过hashcode equals方法重写
public class Hashmapdemo2 {
    public static void main(String[] args) {
        HashMap<Teacher,String> hm= new HashMap<>();
        Teacher t1 =new Teacher("zhangsan",23);
        Teacher t2 =new Teacher("lisi",22);
        Teacher t3 =new Teacher("wangwu",33);
        Teacher t4 =new Teacher("sunliu",31);
        Teacher t5 =new Teacher("sunliu",31);
        hm.put(t1,"001");
        hm.put(t2,"002");
        hm.put(t3,"003");
        hm.put(t4,"004");
        hm.put(t4,"005");
        Set<Teacher> keySet = hm.keySet();
        for (Teacher key : keySet) {
            String values = hm.get(key);
            System.out.println(key+" "+values);
        }
        System.out.println("================");
        Set<Map.Entry<Teacher, String>> entrySet = hm.entrySet();
        for (Map.Entry<Teacher, String> ss : entrySet) {
            Teacher key = ss.getKey();
            String  value = ss.getValue();
            System.out.println(key+" "+value);
        }


    }
}
